From 0a3db8b7090247e51d282052ff1bf0efa1f48cd2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Feb 2017 23:04:24 +0300 Subject: [PATCH] Normalize ws root path closes #3586 --- src/cargo/util/important_paths.rs | 3 ++- tests/workspaces.rs | 33 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/important_paths.rs b/src/cargo/util/important_paths.rs index 5ee44cf20..97e7eed1c 100644 --- a/src/cargo/util/important_paths.rs +++ b/src/cargo/util/important_paths.rs @@ -1,6 +1,7 @@ use std::fs; use std::path::{Path, PathBuf}; use util::{CargoResult, human}; +use util::paths; /// Iteratively search for `file` in `pwd` and its parents, returning /// the path of the directory. @@ -38,7 +39,7 @@ pub fn find_root_manifest_for_wd(manifest_path: Option, cwd: &Path) -> CargoResult { match manifest_path { Some(path) => { - let absolute_path = cwd.join(&path); + let absolute_path = paths::normalize_path(&cwd.join(&path)); if !absolute_path.ends_with("Cargo.toml") { bail!("the manifest-path must be a path to a Cargo.toml file") } diff --git a/tests/workspaces.rs b/tests/workspaces.rs index dc3860f27..0ae7a609a 100644 --- a/tests/workspaces.rs +++ b/tests/workspaces.rs @@ -1102,6 +1102,39 @@ fn relative_path_for_member_works() { assert_that(p.cargo("build").cwd(p.root().join("bar")), execs().with_status(0)); } +#[test] +fn relative_path_for_root_works() { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.1.0" + authors = [] + + [workspace] + + [dependencies] + subproj = { path = "./subproj" } + "#) + .file("src/main.rs", "fn main() {}") + .file("subproj/Cargo.toml", r#" + [project] + name = "subproj" + version = "0.1.0" + authors = [] + "#) + .file("subproj/src/main.rs", "fn main() {}"); + p.build(); + + assert_that(p.cargo("build").cwd(p.root()) + .arg("--manifest-path").arg("./Cargo.toml"), + execs().with_status(0)); + + assert_that(p.cargo("build").cwd(p.root().join("subproj")) + .arg("--manifest-path").arg("../Cargo.toml"), + execs().with_status(0)); +} + #[test] fn path_dep_outside_workspace_is_not_member() { let p = project("foo") -- 2.30.2